﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Future.FormTest
{
    public partial class WcfInsertForm : Form
    {
        string _errMsg;
        public WcfInsertForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Channel.Task task = new Channel.Task();
            task.DALName = Contract.TaskDALEnums.xHeadDAL;
            task.CommandName = Contract.TaskCommandEnums.Insert;
            Entities.xHeadEntity headEntity = new Entities.xHeadEntity();
            headEntity.HeadID_PK = 1;
            headEntity.sName = "Test Update";
            headEntity.iEnable = true;
            headEntity.dDate = DateTime.Now;
            headEntity.iMoney = 1000.8;
            headEntity.State = Contract.EntityState.Select;

            List<Contract.BaseEntity> childEntity = new List<Contract.BaseEntity>();
            for (int n = 0; n < 3; n++)
            {
                Entities.xDetailEntity detailEntity = new Entities.xDetailEntity();
                detailEntity.State = Contract.EntityState.None;
                detailEntity.DetailID_PK = n + 1;
                detailEntity.HeadID_PK = 1;
                detailEntity.sDetailName = "Detail Update";
                detailEntity.iDetailEnable = false;
                detailEntity.iDetailMoney = 111.88 * n;
                detailEntity.dDetailDate = DateTime.Now;
                childEntity.Add(detailEntity);
            }
            headEntity.ChildItem = childEntity;

            task.BufferArgument = Common.ZipTools.CompressionObject<Entities.xHeadEntity>(headEntity);

            bool bRet = Future.WcfClient.ClientProcess.shareXProcess().XClient.ExecCommand(ref task, ref _errMsg);
            if (bRet)
            {
                MessageBox.Show("Success");
            }
            else
            {
                MessageBox.Show(_errMsg);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Channel.Task task = new Channel.Task();
            task.DALName = Contract.TaskDALEnums.xDetailDAL;
            task.CommandName = Contract.TaskCommandEnums.Delete;

            Entities.xDetailEntity detailEntity = new Entities.xDetailEntity();
            detailEntity.State = Contract.EntityState.Select;
            detailEntity.DetailID_PK = 1;
            detailEntity.HeadID_PK = 1;
            detailEntity.sDetailName = "Detail Update";
            detailEntity.iDetailEnable = false;
            detailEntity.iDetailMoney = 111.88;
            detailEntity.dDetailDate = DateTime.Now;


            task.BufferArgument = Common.ZipTools.CompressionObject<Entities.xDetailEntity>(detailEntity);

            bool bRet = Future.WcfClient.ClientProcess.shareXProcess().XClient.ExecCommand(ref task, ref _errMsg);
            if (bRet)
            {
                MessageBox.Show("Success");
            }
            else
            {
                MessageBox.Show(_errMsg);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Channel.Task task = new Channel.Task();
            task.DALName = Contract.TaskDALEnums.xHeadDAL;
            task.CommandName = Contract.TaskCommandEnums.Delete;
            Entities.xHeadEntity headEntity = new Entities.xHeadEntity();
            headEntity.HeadID_PK = 2;
            headEntity.sName = "Test Update";
            headEntity.iEnable = true;
            headEntity.dDate = DateTime.Now;
            headEntity.iMoney = 1000.8;
            headEntity.State = Contract.EntityState.Select;

            List<Contract.BaseEntity> childEntity = new List<Contract.BaseEntity>();
            for (int n = 1; n < 3; n++)
            {
                Entities.xDetailEntity detailEntity = new Entities.xDetailEntity();
                detailEntity.State = Contract.EntityState.Select;
                detailEntity.DetailID_PK = n + 1;
                detailEntity.HeadID_PK = 1;
                detailEntity.sDetailName = "Detail Update";
                detailEntity.iDetailEnable = false;
                detailEntity.iDetailMoney = 111.88 * n;
                detailEntity.dDetailDate = DateTime.Now;
                childEntity.Add(detailEntity);
            }
            headEntity.ChildItem = childEntity;

            task.BufferArgument = Common.ZipTools.CompressionObject<Entities.xHeadEntity>(headEntity);

            bool bRet = Future.WcfClient.ClientProcess.shareXProcess().XClient.ExecCommand(ref task, ref _errMsg);
            if (bRet)
            {
                MessageBox.Show("Success");
            }
            else
            {
                MessageBox.Show(_errMsg);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Channel.Task task = new Channel.Task();
            task.DALName = Contract.TaskDALEnums.xHeadDAL;
            task.CommandName = Contract.TaskCommandEnums.Select;

            Entities.xHeadEntity detailEntity = new Entities.xHeadEntity();
            detailEntity.sName = "Update";

            task.BufferArgument = Common.ZipTools.CompressionObject<Entities.xHeadEntity>(detailEntity);

            bool bRet = Future.WcfClient.ClientProcess.shareXProcess().XClient.ExecCommand(ref task, ref _errMsg);
            if (bRet)
            {
                MessageBox.Show("Success");
            }
            else
            {
                MessageBox.Show(_errMsg);
            }
        }
    }
}
